﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}
<script type="text/javascript">
    $(function () {
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);

    });
</script>
<script type="text/javascript">
    var columns = [[
               {
                   field: 'ck', checkbox: true, width: 30
               },
                {
                    field: 'Name', title: '权限名称', width: 100, align: "center", editor: {
                        type: "validatebox",
                        options: {
                            required: true
                        }
                    }
                },
                {
                    field: 'Parent', title: '父类', width: 100, align: "center", editor: {
                        type: "combobox",
                        options: {
                            url: '/Permission/GetParentPerm',
                            valueField: 'value',
                            textField: 'text',
                            required: true
                        }
                    }, formatter: function (value, row, index) {
                        return row.ParentName
                    }
                },
             {
                 field: 'OrderField', title: '排序', width: 80, align: "center", editor: {
                     type: "validatebox",
                     options: {
                     }
                 }
             },
           {
               field: 'LinkUrl', title: '链接地址', width: 250, align: "center", editor: {
                   type: "validatebox",
                   options: {
                   }
               }
                },
              //  {
         //      field: 'IsShow', title: '是否显示', width: 80, align: "center", filterColumns: [{ text: "是", value: "0", state: true }, { text: "否", value: "1", state: true }], editor: {
         //          type: "combobox",
         //          options: {
         //              data: StaticCombo.PermissionIsShow,
         //              valueField: 'value',
         //              textField: 'text',
         //              required: true
         //          }
         //      }, formatter: function (value, row, index) {
         //          return value == "0" ? "是" : value == "1" ? "否" : "";
         //      }
         //  },
         //{
         //    field: 'IsShortCut', title: '是否快捷方式', width: 110, align: "center", filterColumns: [{ "是": true }, { "否": true }], editor: {
         //        type: "combobox",
         //        options: {
         //            data: StaticCombo.IsShortCut,
         //            valueField: 'value',
         //            textField: 'text',
         //            required: true
         //        }
         //    }, formatter: function (value, row, index) {
         //        return com.getArrayText(StaticCombo.IsShortCut, value);
         //        // return value == "0" ? "是" : value == "1" ? "否" : "";
         //    }
         //}, {
         //    field: 'ShortCutPic', title: '快捷方式图标', width: 100, align: "center", editor: {
         //        type: "validatebox",
         //        options: {
         //        }
         //    }
         //}, 
         {
             field: 'IsFatherNode', title: '是否父节点', width: 80, align: "center", editor: {
                 type: "combobox",
                 options: {
                     data: StaticCombo.IsFatherNode,
                     valueField: 'value',
                     textField: 'text',
                     required: true
                 }
             }, formatter: function (value, row, index) {
                 return com.getArrayText(StaticCombo.IsFatherNode, value);
                 // return value == "0" ? "是" : value == "1" ? "否" : "";
             }
         },
    {
        field: 'Note', title: '备注', width: 100, align: "center", editor: {
            type: "validatebox",
            options: {
                validType: ['length[0,50]']

            }
        }
    },
    {
        field: 'AddTime', title: '维护时间', width: 100, align: "center"
    }, {
        field: 'Clerk', title: '维护人', width: 100, align: "center"
    }
    ]]

    $(function () {
        $("#tbList").datagrid({
            url: '/Permission/List',
            loadMsg: '数据加载中请稍后……',
            pagination: true,
            rownumbers: true,
            idField: "Id",
            border: true,
            columns: columns,
            noheader: true,
            remoteSort: false,//是否从服务器排序
            queryParams: com.serializeSearchArray("form1"),
            singleSelect: true,
            pageSize: 20,
            pageList: [20, 50, 100],
            striped: true,
            onAfterEdit: function (rowIndex, rowData, changes) {
                //rowIndex，该结束行的索引
                //console.info(row);
                // console.log(rowData);
                if (editAction == "edit") {
                    com.ajax({
                        url: "/Permission/EditPermission",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                } else if (editAction == "add") {
                    com.ajax({
                        url: "/Permission/AddPermission",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                }
                editRow = undefined;
            }, onCancelEdit: function (rowIndex, rowData) {
                $("#tbList").datagrid("rejectChanges");

            }

        });
    })


</script>
<script>
    editRow = undefined;
    editAction = undefined;
    function funcSearch() {
        var para = com.serializeSearchArray("form1");
        var target = $("#tbList")[0];
        state = $.data(target, "datagrid");
        opts = state.options;
        opts.queryParams.searchData = para.searchData;
        $("#tbList").datagrid("load", opts.queryParams);

    }
    function funcAdd() {
        //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
        if (editRow != undefined) {

        }
        //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
        if (editRow == undefined) {
            $("#tbList").datagrid("insertRow", {
                index: 0, // index start with 0
                row: {

                }
            });
            //将新插入的那一行开户编辑状态
            $("#tbList").datagrid("beginEdit", 0);
            //给当前编辑的行赋值
            editRow = 0;
            editAction = "add";
        }
    }
    function funcEdit() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            if (editRow != undefined) {
            }
            else {
                var index = $("#tbList").datagrid('getRowIndex', row);
                //   var index = row.Id;
                $("#tbList").datagrid('beginEdit', index);
                editAction = "edit";
                editRow = index;
            }
        }
        else {
            com.message("information", "请选中一行");
        }
    }
    function funcRemove() {
        $.messager.confirm('确认对话框', '您确定删除该权限吗？', function (r) {
            if (r) {
                var rowData = $("#tbList").datagrid("getSelected");
                if (rowData) {
                    com.ajax({
                        url: '/Permission/DelPermission',
                        data: { Id: rowData.Id },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })
                        }
                    });
                }
            }
        });
    }

    function funcSave() {
        $('#tbList').datagrid('endEdit', editRow);
    }
    function funcCancel() {
        $('#tbList').datagrid("cancelEdit", editRow);
        editRow = undefined;
        editAction = undefined;
    }
    function funcReload() {
        $("#form1").form("reset");
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div style="margin:5px" id="master">
        <form id="form1">
            <input id="Name" name="Name" class="easyui-textbox" data-options="prompt:'权限名称'" data-cp="co">
            <input id="ParentName" name="ParentName" class="easyui-textbox" data-options="prompt:'父类名称'" data-cp="co">
        </form>
    </div>
    <table id="tbList" title="权限信息表 " style="width: 100%"></table>
</div>